{{template "header.html" .}}
{{$g := .GraphOptions}}

<ul class="breadcrumb">
  <li><a href="/">Streams</a> <span class="divider">/</span></li>
  <li><a href="/topic/{{.Topic}}">{{.Topic}}</a> <span class="divider">/</span></li>
  <li class="active">{{.Channel}}</li>
</ul>

<div class="row-fluid">
    <div class="span6">
        <blockquote>
            <p>Topic: <strong>{{.Topic}}</strong>
            <p>Channel: <strong>{{.Channel}}</strong>
        </blockquote>
    </div>
</div>

{{if not .ChannelStats}}
<div class="row-fluid">
    <div class="span6">
        <div class="alert">
            <h4>Notice</h4> No producers exist for this topic/channel.
            <p>See <a href="/lookup">Lookup</a> for more information.
        </div>
    </div>
</div>
{{else}}
<div class="row-fluid">
    <div class="span2">
        <form action="/empty_channel" method="POST">
            <input type="hidden" name="topic" value="{{.ChannelStats.Topic}}">
            <input type="hidden" name="channel" value="{{.ChannelStats.ChannelName}}">
            <button class="btn btn-medium btn-warning" type="submit">Empty Queue</button>
        </form>
    </div>
    <div class="span2">
        <form action="/delete_channel" method="POST">
            <input type="hidden" name="topic" value="{{.ChannelStats.Topic}}">
            <input type="hidden" name="channel" value="{{.ChannelStats.ChannelName}}">
            <button class="btn btn-medium btn-danger" type="submit">Delete Channel</button>
        </form>
    </div>
    <div class="span2">
        {{if .ChannelStats.Paused}}
        <form action="/unpause_channel" method="POST">
            <input type="hidden" name="topic" value="{{.ChannelStats.Topic}}">
            <input type="hidden" name="channel" value="{{.ChannelStats.ChannelName}}">
            <button class="btn btn-medium btn-success" type="submit">UnPause Channel</button>
        </form>
        {{else}}
        <form action="/pause_channel" method="POST">
            <input type="hidden" name="topic" value="{{.ChannelStats.Topic}}">
            <input type="hidden" name="channel" value="{{.ChannelStats.ChannelName}}">
            <button class="btn btn-medium btn-inverse" type="submit">Pause Channel</button>
        </form>
        {{end}}
    </div>
</div>

<div class="row-fluid"><div class="span12">
<h4>Channel</h4>
<table class="table table-bordered table-condensed">
    <thead>
        <tr>
            <th>&nbsp;</th>
            <th colspan="4" class='text-center'>Message Queues</th>
            {{if $g.Enabled}}
            <th colspan="4" class='text-center'>Statistics</th>
            {{else}}
            <th colspan="5" class='text-center'>Statistics</th>
            {{end}}
        </tr>
        <tr>
            <th>Host</th>
            <th>Depth</th>
            <th>Memory + Disk</th>
            <th>In-Flight</th>
            <th>Deferred</th>
            <th>Requeued</th>
            <th>Timed Out</th>
            <th>Messages</th>
            {{if $g.Enabled}}<th>Rate</th>{{end}}
            <th>Connections</th>
        </tr>
    </thead>
    <tbody>

{{range $c := .ChannelStats.HostStats}}
        <tr>
            <td>{{$c.HostAddress}}{{if $c.Paused}} <span class="label label-important">paused</span>{{end}}</td>
            <td>{{$c.Depth | commafy}}</td>
            <td>{{$c.MemoryDepth | commafy}} + {{$c.BackendDepth | commafy}}</td>
            <td>{{$c.InFlightCount | commafy}}</td>
            <td>{{$c.DeferredCount | commafy}}</td>
            <td>{{$c.RequeueCount | commafy}}</td>
            <td>{{$c.TimeoutCount | commafy}}</td>
            <td>{{$c.MessageCount | commafy}}</td>
            {{if $g.Enabled}}<td class="bold rate" target="{{$g.Rate $c}}"></td> {{end}}
            <td>{{$c.ClientCount}}</td>
        </tr>
        {{if $g.Enabled}}
        <tr>
            <td></td>
            <td><a href="{{$g.LargeGraph $c "depth"}}"><img width="120" height="20"  src="{{$g.Sparkline $c "depth"}}"></a></td>
            <td></td>
            <td><a href="{{$g.LargeGraph $c "in_flight_count"}}"><img width="120" height="20"  src="{{$g.Sparkline $c "in_flight_count"}}"></a></td>
            <td><a href="{{$g.LargeGraph $c "deferred_count"}}"><img width="120" height="20"  src="{{$g.Sparkline $c "deferred_count"}}"></a></td>
            <td><a href="{{$g.LargeGraph $c "requeue_count"}}"><img width="120" height="20"  src="{{$g.Sparkline $c "requeue_count"}}"></a></td>
            <td><a href="{{$g.LargeGraph $c "timeout_count"}}"><img width="120" height="20"  src="{{$g.Sparkline $c "timeout_count"}}"></a></td>
            <td><a href="{{$g.LargeGraph $c "message_count"}}"><img width="120" height="20"  src="{{$g.Sparkline $c "message_count"}}"></a></td>
            <td></td>
            <td><a href="{{$g.LargeGraph $c "clients"}}"><img width="120" height="20"  src="{{$g.Sparkline $c "clients"}}"></a></td>
        </tr>
        {{end}}

{{ end }}
{{ with $c := .ChannelStats }}
        <tr class="info">
            <td>Total:</td>
            <td>{{$c.Depth | commafy}}</td>
            <td>{{$c.MemoryDepth | commafy}} + {{$c.BackendDepth | commafy}}</td>
            <td>{{$c.InFlightCount | commafy}}</td>
            <td>{{$c.DeferredCount | commafy}}</td>
            <td>{{$c.RequeueCount | commafy}}</td>
            <td>{{$c.TimeoutCount | commafy}}</td>
            <td>{{$c.MessageCount | commafy}}</td>
            {{if $g.Enabled}}<td class="bold rate" target="{{$g.Rate $c}}"></td> {{end}}
            <td>{{$c.ClientCount}}</td>
        </tr>
        {{if $g.Enabled}}
        <tr class="info">
            <td></td>
            <td><a href="{{$g.LargeGraph $c "depth"}}"><img width="120" height="20"  src="{{$g.Sparkline $c "depth"}}"></a></td>
            <td></td>
            <td><a href="{{$g.LargeGraph $c "in_flight_count"}}"><img width="120" height="20"  src="{{$g.Sparkline $c "in_flight_count"}}"></a></td>
            <td><a href="{{$g.LargeGraph $c "deferred_count"}}"><img width="120" height="20"  src="{{$g.Sparkline $c "deferred_count"}}"></a></td>
            <td><a href="{{$g.LargeGraph $c "requeue_count"}}"><img width="120" height="20"  src="{{$g.Sparkline $c "requeue_count"}}"></a></td>
            <td><a href="{{$g.LargeGraph $c "timeout_count"}}"><img width="120" height="20"  src="{{$g.Sparkline $c "timeout_count"}}"></a></td>
            <td><a href="{{$g.LargeGraph $c "message_count"}}"><img width="120" height="20"  src="{{$g.Sparkline $c "message_count"}}"></a></td>
            <td></td>
            <td><a href="{{$g.LargeGraph $c "clients"}}"><img width="120" height="20"  src="{{$g.Sparkline $c "clients"}}"></a></td>
        </tr>
        {{end}}
    </tbody>
{{ end }}
</table>
</div></div>

<h4>Client Connections</h4>

<div class="row-fluid"><div class="span12">
{{if not .ChannelStats.Clients}}
<div class="alert"><h4>Notice</h4>No clients connected to this channel</div>
{{else}}
<table class="table table-bordered table-condensed">
    <tr>
        <th>Client Host</th>
        <th>Protocol</th>
        <th>NSQd Host</th>
        <th>In-Flight</th>
        <th>Ready Count</th>
        <th>Finished</th>
        <th>Requeued</th>
        <th>Messages</th>
        <th>Connected</th>
    </tr>

{{range .ChannelStats.Clients}}
    <tr>
        <td>{{.ClientIdentifier}}</td>
        <td>{{.ClientVersion}}</td>
        <td>{{.HostAddress}}</td>
        <td>{{.InFlightCount | commafy}}</td>
        <td>{{.ReadyCount | commafy}}</td>
        <td>{{.FinishCount | commafy}}</td>
        <td>{{.RequeueCount | commafy}}</td>
        <td>{{.MessageCount | commafy}}</td>
        <td>{{.ConnectedDuration}}</td>
    </tr>
{{end}}
</table>
{{end}}
</div></div>
{{end}}

{{template "js.html" .}}
{{template "footer.html" .}}
